package com.quick.threadtest;

import java.util.concurrent.locks.ReentrantLock;

public class TicketsThread implements Runnable{
    public static int t = 100;
    ReentrantLock reentrantLock = new ReentrantLock();
    @Override
    public void run(){
        try {
            for (;;){
                reentrantLock.lock();
                if (t>0){
                    System.out.printf("%s线程正在卖出第%d张票\n",
                            Thread.currentThread().getName(), t--);
                }else {
                    break;
                }
            }
        }catch (Exception e){
        }finally {
            reentrantLock.unlock();
        }

    }
}
